<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreatePledgeMovables extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('pledge_movables', function (Blueprint $table) {
            $table->id()->from(config('migration.from'));

            $table->string('name')->nullable()->comment('Наименование');

            $table->string('brand_model')->nullable()->comment('Марка,Модель ТС');
            $table->year('year')->nullable()->comment('Год изготовления ТС');
            $table->string('body')->nullable()->comment('Кузов');
            $table->string('engine_volume')->nullable()->comment('Объем двигателя');
            $table->string('engine_type')->nullable()->comment('Тип двигателя');
            $table->string('chassis')->nullable()->comment('Шасси');
            $table->string('body_color')->nullable()->comment('Цвет кузова');
            $table->string('engine_model_number')->nullable()->comment('Модель,Номер двигателя');
            $table->string('engine_power')->nullable()->comment('Мощность двигателя');

            $table->string('vin')->nullable()->comment('VIN');

            $table->string('ts_mfr')->nullable()->comment('Изготовитель ТС');

            $table->date('pts_date')->nullable()->comment('Дата выдачи');
            $table->string('pts_series_number')->nullable()->comment('Серия,Номер ПТС');
            $table->char('pts_issued_by')->nullable()->comment('Кем выдан');
            $table->text('pts_issued_address')->nullable()->comment('Адрес');

            $table->jsonb('pts_scans')->default(json_encode([]))->comment('Скан ПТС');
            $table->index('pts_scans', null, 'gin');

            $table->date('sts_date')->nullable()->comment('Дата выдачи');
            $table->string('sts_series_number')->nullable()->comment('Серия,Номер СТС');
            $table->string('sts_issued_by')->nullable()->comment('Кем выдан');

            $table->jsonb('sts_scans')->default(json_encode([]))->comment('Скан СТС');
            $table->index('sts_scans', null, 'gin');

            $table->string('gos_number')->nullable()->comment('Госномер');
            $table->text('address')->nullable()->comment('Адрес');

            $table->text('other_information')->nullable()->comment('Иные сведения');

            $table->jsonb('documents')->default(json_encode([]))->comment('Иные документы');
            $table->index('documents', null, 'gin');

            $table->jsonb('images')->default(json_encode([]))->comment('Фото залога');
            $table->index('images', null, 'gin');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('pledge_movables');
    }
}
